//
//  UIGestureRecognizer+Block.m
//  YDGJ
//
//  Created by ydcq on 16/9/18.
//  Copyright © 2016年 Galaxy360. All rights reserved.
//

#import "UIGestureRecognizer+Block.h"
#import <objc/runtime.h>

static const void *blkKey = @"blkKey";

@implementation UIGestureRecognizer (Block)

- (void)addGestureOnView:(UIView *)view WithBlock:(void(^)(void))blk
{
    objc_setAssociatedObject(self, blkKey, blk, OBJC_ASSOCIATION_COPY_NONATOMIC);
    [view addGestureRecognizer:self];
    [self addTarget:self action:@selector(gestureBlock)];
}

- (void)gestureBlock
{
    void (^blk)() = objc_getAssociatedObject(self, blkKey);
    if (blk) {
        blk();
    }
}

@end
